package com.example.easyscript.config;

import com.example.easyscript.config.properties.Knife4jProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import javax.annotation.Resource;

@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfiguration {

    @Resource
    Knife4jProperties knife4jProperties;

    @Bean(value = "defaultApi")
    public Docket defaultApi() {

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title(knife4jProperties.getTitle())
                        .description(knife4jProperties.getDescription())
                        .termsOfServiceUrl(knife4jProperties.getTermsOfServiceUrl())
                        .contact(new Contact(knife4jProperties.getName(), knife4jProperties.getTermsOfServiceUrl(), knife4jProperties.getEmail()))
                        .version(knife4jProperties.getVersion())
                        .build())
                //分组名称
                .groupName(knife4jProperties.getGroupName())
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage(knife4jProperties.getBasePackage()))
                .paths(PathSelectors.any())
                .build();

    }
}
